package com.java.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.java.system.entity.Area;
import com.java.system.entity.Camera;
import com.java.system.mapper.AreaMapper;
import com.java.system.service.IAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoman
 * @since 2023-07-12
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {
    @Autowired
    AreaMapper areaMapper;

    @Override
    public List<Area> getArea() {
        LambdaQueryWrapper<Area> queryWrapper=new LambdaQueryWrapper<>();
        List<Area> areaList = areaMapper.selectList(queryWrapper);
        if(!StringUtils.isEmpty(areaList)){
            return areaList;
        }
        else {
            return null;
        }
    }

    @Override
    public List<Camera> getCameraListById(Integer id) {
        List<Camera> cameraList = areaMapper.getCameraListById(id);
        if(!StringUtils.isEmpty(cameraList)){
            return cameraList;
        }
        else {
            return null;
        }
    }

    @Override
    public void insertArea(Area area) {
        areaMapper.insert(area);
    }

    @Override
    public Area getAreaById(Integer id) {
        Area area = areaMapper.selectById(id);
        if(area!=null){
            return area;
        }
        else {
            return null;
        }
    }

    @Override
    public void updateArea(Area area) {
        areaMapper.updateById(area);
    }

    @Override
    public void deleteArea(Integer id) {
        areaMapper.deleteById(id);
    }
}
